package main

import (
	"fmt"
	"math"
	"sort"
	"strconv"
	"strings"
)


func reverse(x int) int {
	if x ==0{
		return 0
	}
	//将数字转字符串
	xStr:=strconv.Itoa(x)
	//字符串遍历，转切片,获取索引切片
	var index []int
	for i, _ := range xStr {
		index = append(index, i)
	}
	//反转索引切片
	sort.Sort(sort.Reverse(sort.IntSlice(index)))
	//拼接字符串
	var s string
	for _, i := range index {
		s += string(xStr[i])
	}
	ok:=strings.HasPrefix(s, "0")
	if ok{
		s = strings.TrimLeft(s, "0")
	}
	if x < 0{
		//去除最后的负号
		s = "-" + s[:len(s)-1]
	}
	//转数字
	num, _:= strconv.ParseInt(s, 10, 64)
	res := int(num)
	if res >int(math.Pow(2 ,31))-1 || res < int(math.Pow(-2 ,31)){
		return 0
	}
	return res

}
func main() {
	fmt.Println(reverse(1534236469))
}